package com.frejoys.dao.util;

import cn.hutool.core.bean.BeanUtil;
import com.frejoys.common.util.TimeUtil;
import com.frejoys.common.vo.common.AppVersionVo;
import com.frejoys.dao.entity.AppVersion;

import java.util.ArrayList;
import java.util.List;

// 转换 entity 为 vo
public class AppVersionVoUtil {

    public static AppVersionVo toVo(AppVersion e) {
        AppVersionVo vo = null;
        if (e != null && e.getUpgradeTime() < TimeUtil.unixTime()) {
            vo = new AppVersionVo();
            BeanUtil.copyProperties(e, vo);
        }
        return vo;
    }

    public static List<AppVersionVo> toVo(List<AppVersion> es) {
        List<AppVersionVo> list = new ArrayList<>();
        if (!es.isEmpty()) {
            for (AppVersion e : es) {
                AppVersionVo vo = new AppVersionVo();
                BeanUtil.copyProperties(e, vo);
                list.add(vo);
            }
        }
        return list;
    }

}
